package com.gpio;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class XmlUtil {
	public static Map<String, Object> xmlToMap(String xmlStr) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			Document document = DocumentHelper.parseText(xmlStr);
			Element root = document.getRootElement();
			Iterator<Element> i = root.elementIterator();
			while (i.hasNext()) {
				Element e = i.next();
				result.put(e.getName(), e.getData());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
